import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { isPhone } from "@pureadmin/utils";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
	companyName: [{ required: true, message: "公司名称为必填项", trigger: "blur" }],
	address: [{ required: true, message: "地址为必填项", trigger: "blur" }],

	phoneNumber: [
		{ required: true, message: "电话号码为必填项", trigger: "blur" },
		{
			validator: (rule, value, callback) => {
				if (value === "") {
					callback();
				} else if (!isPhone(value)) {
					callback(new Error("请输入正确的手机号码格式"));
				} else {
					callback();
				}
			},
			trigger: "blur"
		}
	]
});
